package remato.domain.server.ejb;

import static javax.persistence.EnumType.STRING;
import static javax.persistence.GenerationType.AUTO;

import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.Transient;

import remato.common.domain.property.PropertyTypeEnum;
import remato.common.domain.property.PropertyTypeEnumImpl;
import remato.domain.common.PropertyDef;
import remato.domain.common.impl.PropertyDefImpl;

/**
 * 
 * @author petterei
 * @version $Id: PropertyDefEjb.java,v 1.2 2006-02-06 09:22:24 petterei Exp $
 */
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class PropertyDefEjb extends PropertyDefImpl implements PropertyDef {

	@Override
	@Id
	@GeneratedValue(strategy=AUTO)
	public Long getDbId() {
		return super.getDbId();
	}
	
	@Override
	public String getDefaultValue() {
		return super.getDefaultValue();
	}

	@Override
	@Lob
	public String getDescription() {
		return super.getDescription();
	}

	@Override
	public String getName() {
		return super.getName();
	}

	@Override
	@Transient
	public PropertyTypeEnum getPropertyTypeEnum() {
		return getPersistablePropertyType();
//		return PropertyTypeImpl.valueOf(getPropertyTypeDueToHibEnumBug());
	}
	
	@Override
	public void setPropertyTypeEnum(PropertyTypeEnum type) {
		setPersistablePropertyType((PropertyTypeEnumImpl)type);
		
	}
	
	/*
	 * "Wrappers" to make hibernate understand that this is a enum, while only
	 * the interface is exposed to clients. 
	 * 
	 * Hibernate does not support (yet?) to define targetEntity or targetClass
	 * to arrange for use of interfaces in combination with enums.
	 */
	@Enumerated(STRING) // EnumType  'STRING' is used to ensure consistensy
	public PropertyTypeEnumImpl getPersistablePropertyType() {
		return (PropertyTypeEnumImpl)super.getPropertyTypeEnum();
	}
	
	/*
	 * "Wrappers" to make hibernate understand that this is a enum, while only
	 * the interface is exposed to clients. 
	 * 
	 * Hibernate does not support (yet?) to define targetEntity or targetClass
	 * to arrange for use of interfaces in combination with enums.
	 */
	public void setPersistablePropertyType(PropertyTypeEnumImpl type) {
		super.setPropertyTypeEnum(type);
	}
	
	/**
	 * Needed to trigger CGLib proxy (ie. if other CGLib-proxies is used as 
	 * parameter.)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}

}
